//
//  PaperReportViewModel.swift
//  Exam-iOS
//
//  Created by lishengfeng on 2018/3/14.
//  Copyright © 2018年 李胜锋. All rights reserved.
//

import Foundation
import RxSwift
import RxCocoa
import RxDataSources

class PaperReportViewModel {
    var disposeBag = DisposeBag()
    
    let paper: PaperModel
    var vmDatas = Variable([PaperReportSection]())
    
    ///是否已经自评分
    var hasSelfeScore: Bool = false
    
    init(_ paper: PaperModel) {
        self.paper = paper
    }
    
    public func transform() {
        var sections = [PaperReportSection]()
        //单选题
        if let items = paper.paperItemsFor(.radio), items.count > 0 {
            let header = "单项选择题"
            let section = PaperReportSection.init(header: header, items: items)
            sections.append(section)
        }
        
        //多选题
        if let items = paper.paperItemsFor(.multiSelect), items.count > 0 {
            let header = "多项选择题"
            let section = PaperReportSection.init(header: header, items: items)
            sections.append(section)
        }
        
        //判断题
        if let items = paper.paperItemsFor(.trueOrFalse), items.count > 0 {
            let header = "判断题"
            let section = PaperReportSection.init(header: header, items: items)
            sections.append(section)
        }
        
        //简答题
        if let items = paper.paperItemsFor(.shortAnswer), items.count > 0 {
            let header = "简答题"
            let section = PaperReportSection.init(header: header, items: items)
            sections.append(section)
        }
        
        //计算题
        if let items = paper.paperItemsFor(.calculation), items.count > 0 {
            let header = "计算题"
            let section = PaperReportSection.init(header: header, items: items)
            sections.append(section)
        }
        
        //案例分析题
        if let items = paper.paperItemsFor(.analysis), items.count > 0 {
            let header = "综合分析题"
            let section = PaperReportSection.init(header: header, items: items)
            sections.append(section)
        }
        
        //公文筐测验
        if let items = paper.paperItemsFor(.in_trayTest), items.count > 0 {
            let header = "公文筐测验"
            let section = PaperReportSection.init(header: header, items: items)
            sections.append(section)
        }
        
        vmDatas.value = sections
    }
}


struct PaperReportSection {
    var header: String
    var items: [PaperItemModel]
}

extension PaperReportSection: SectionModelType {
    typealias Item = PaperItemModel
    
    init(original: PaperReportSection, items: [PaperItemModel]) {
        
        self = original
        self.items = items
    }
}
